﻿using System;
using System.Collections.Generic;

namespace exercise1
{
	class exercise1
	{
		static void Main(string[] args)
		{
			Console.WriteLine("请输入数组的内容(每个数字之间用“,”隔开)：");
			int[] arr = { 12, 24, 45, 31, 52, 61, 7 };
			int max = MaxOne(arr);
			int min = MinOne(arr);
			int avg = AvgOne(arr);
			int sum = SumOne(arr);
			Console.WriteLine("数组的最大值是：" + max);
			Console.WriteLine("数组的最小值是：" + min);
			Console.WriteLine("数组的平均数是：" + avg);
			Console.WriteLine("数组的总和是：" + sum);

		}

		private static int SumOne(int[] arr)
		{
			if (arr == null) return 0;
			int sum = 0;
			for (int i = 0; i < arr.Length; i++)
			{
				sum = sum + arr[i];
			}
			return sum;
		}

		private static int AvgOne(int[] arr)
		{
			if (arr == null) return 0;
			int sum = 0;
			int avg;
			for (int i = 0; i < arr.Length; i++)
			{
				sum = arr[i] + sum;
			}
			avg = sum / arr.Length;
			return avg;
		}

		private static int MinOne(int[] arr)
		{
			if (arr == null) return 0;
			int min = arr[0];
			for (int i = 0; i < arr.Length; i++)
			{
				if (arr[i] < min)
				{
					min = arr[i];
				}

			}
			return min;
		}

		private static int MaxOne(int[] arr)
		{
			if (arr == null) return 0;
			int max = arr[0];
			for (int i = 0; i < arr.Length; i++)
			{
				if (arr[i] > max)
				{
					max = arr[i];
				}

			}
			return max;
		}

	}
}